﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>GUI 控件类型 - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="GUI control types are elements of interaction which can be added to a GUI window using the Gui object's Add method." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
<style>
  img {
    margin: 0 1.5em;
    border: 1px solid silver;
  }
</style>
</head>
<body>

<h1><a href="../objects/Gui.htm">GUI</a> 控件类型</h1>

<h2 id="Table_of_Contents">目录</h2>
<ul>
  <li><a href="#Text">Text</a>, <a href="#Edit">Edit</a>, <a href="#UpDown">UpDown</a>, <a href="#Picture">Picture</a></li>
  <li><a href="#Button">Button</a>, <a href="#Checkbox">Checkbox</a>, <a href="#Radio">Radio</a></li>
  <li><a href="#DropDownList">DropDownList</a>, <a href="#ComboBox">ComboBox</a></li>
  <li><a href="#ListBox">ListBox</a>, <a href="ListView.htm">ListView</a>, <a href="TreeView.htm">TreeView</a></li>
  <li><a href="#Link">Link</a>, <a href="#Hotkey">Hotkey</a>, <a href="#DateTime">DateTime</a></li>
  <li><a href="#MonthCal">MonthCal</a>, <a href="#Slider">Slider</a>, <a href="#Progress">Progress</a></li>
  <li><a href="#GroupBox">GroupBox</a>, <a href="#Tab">Tab3</a>, <a href="#StatusBar">StatusBar</a></li>
  <li><a href="#ActiveX">ActiveX</a>(例如 Internet Explorer 控件)</li>
  <li><a href="#Custom">Custom</a>(自定义)</li>
</ul>

<h2 id="Text">Text</h2>
<p>描述: 包含用户不能编辑的无边界文本的区域. 常用来标识其他控件.</p>
<p>例如:</p>
<pre>MyGui.Add("Text",, "Please enter your name:")</pre>
<p>外观:</p>
<img src="../static/ctrl_text.png" alt="Text" />
<p>此时最后一个参数为要显示的字符串. 它可以包含换行符(`n) 来开始新行. 此外, 一个长行可以使用<a href="../Scripts.htm#continuation">延续片段</a>的方法分成较短的几行.</p>
<p>如果 <em>Options</em> 中指定了宽度(W) 而没有指定<a href="../objects/Gui.htm#R">行数(R)</a> 或高度(H), 那么在需要时文本将自动换行, 同时自动设置控件的高度.</p>

<p>若要检测用户单击文本, 请使用 <a href="../objects/GuiOnEvent.htm#Click">Click(单击) 事件</a>. 例如:</p>
<pre>MyGui := Gui.New()
FakeLink := MyGui.Add("Text", "", "Click here to launch Google.")
FakeLink.SetFont("underline cBlue")
FakeLink.OnEvent("Click", "LaunchGoogle")

<em>; 或者可以使用 <a href="#Link">Link</a> 控件:</em>
MyGui.Add("Link",, 'Click &lt;a href="www.google.com"&gt;here&lt;/a&gt; to launch Google.')
MyGui.Show()

LaunchGoogle(*) {
    Run("www.google.com")
}</pre>
<p>Text(文本) 控件也支持 <a href="../objects/GuiOnEvent.htm#DoubleClick">DoubleClick(双击) 事件</a>.</p>
<p id="SS_NOTIFY">只有带有 SS_NOTIFY(0x100)  样式的文本控件才能发送单击和双击通知, 因此 <a href="../objects/GuiOnEvent.htm">OnEvent</a> 在注册单击或双击回调时自动添加这种样式. SS_NOTIFY 样式会导致操作系统在双击控件时自动将其文本复制到剪贴板.</p>
<p>在文本中使用和符号(&amp;) 可以让其中的某个字母带下划线. 例如:</p>
<pre>MyGui.Add("Text",, "&amp;First Name:")
MyGui.Add("Edit")</pre>
<p>在上述示例中, 字母 F 将添加下划线, 这允许用户按下<a href="../objects/Gui.htm#ShortcutKey">快捷键</a> <kbd>Alt</kbd>+<kbd>F</kbd> 将键盘焦点设置到此文本控件之后添加的首个可输入型控件中. 要显示一个文字的和符号(&amp;), 请指定两个连续的和符号(&amp;&amp;). 要取消控件中和符号的特殊含义, 请在控件的选项中包含 <a href="../misc/Styles.htm#SS_NOPREFIX">0x80</a>.</p>
<p>有关其他选项, 如 <em>Right</em>, <em>Center</em> 和 <em>Hidden</em>, 请参阅<a href="../objects/Gui.htm#OtherOptions">常规选项</a>. 另请参阅: <a href="../objects/Gui.htm#PosSize">控件的位置和大小</a>.</p>

<h2 id="Edit">Edit</h2>
<p>描述: 用户可以在其中键入自由格式文本的区域.</p>
<p>例如:</p>
<pre>MyGui.Add("Edit", "r9 vMyEdit w135", "Text to appear inside the edit control (omit this parameter to start off empty).")</pre>
<p>外观:</p>
<img src="../static/ctrl_edit.png" alt="Edit" />
<p>如果控件具有多行文本, 则它将是多行的. 例如, 在 <em>Options</em> 中指定 <code>r3</code> 将创建一个 3 行的编辑(Edit) 控件, 并拥有后面这些默认属性: 垂直滚动条, 启用自动换行, 并且 <kbd>Enter</kbd> 键作为输入的一部分, 而不触发窗口的<a href="#DefaultButton">默认按钮</a>.</p>
<p>要在多行编辑控件中开始新行, 请在最后一个参数中(内容) 包含单独的换行符(`n) 或回车换行符(`r`n). 这两种方法都会在编辑控件中产生原义的 `r`n 对. 然而, 当通过 <a href="../objects/Gui.htm#Submit">MyGui.Submit</a> 或 <a href="../objects/GuiControl.htm#Value">GuiCtrl.Value</a> 来检索控件的内容时, 文本中的每对 `r`n 总是被转换成单独的换行符(`n). To bypass this End-of-Line translation, use <a href="../objects/GuiControl.htm#Text">GuiCtrl.Text</a>. 要把文本写入到文件中, 请参照此例: <code><a href="FileAppend.htm">FileAppend</a>(MyEdit.Text, "C:\Saved File.txt")</code>.</p>
<p>如果控件启用了自动换行(对于多行编辑控件默认是启用的), 那么用户输入时任何自动换行的地方不会产生换行字符(仅 <kbd>Enter</kbd> 键才会).</p>
<p>当用户或脚本改变控件的内容时, 触发 <a href="../objects/GuiOnEvent.htm#Change">Change</a> 事件.</p>
<p>提示: 要加载一个文本文件的内容到编辑控件中, 请使用 <a href="FileRead.htm">FileRead</a> 和 <a href="../objects/GuiControl.htm#Value">GuiCtrl.Value</a>. 例如:</p>
<pre>MyEdit := MyGui.Add("Edit", "R20")
MyEdit.Value := FileRead("C:\My File.txt")</pre>

<h3 id="Edit_Options">Edit 选项</h3>
<p>要移除而非添加选项, 请在选项前加上负号:</p>
<p><strong>Limit</strong>: 限制用户的输入在编辑区域的可见宽度内. 另外, 要限制输入指定数目的字符, 请在该选项后跟着数字. 例如, <code>Limit10</code> 将允许输入不超过 10 个字符.</p>
<p><strong>Lowercase</strong>: 把用户输入的字符自动转换成小写形式.</p>
<p id="EditMulti"><strong>Multi</strong>: 让控件可以含有多行文本. 然而, 通常没必要指定此选项, 因为它会根据高度(H), <a href="../objects/Gui.htm#R">行数(R)</a> 或内容(<em>Text</em>) 自动判断.</p>
<p id="EditNum"><strong>Number</strong>: 阻止用户输入数字以外的其他字符到编辑区域(然而, 还是可能粘贴非数字字符到里面). 强制输入数字的另一种方法是添加 <a href="#UpDown">UpDown</a> 控件到编辑控件中.</p>
<p><strong>Password</strong>: 通过将用户输入替换为掩码字符来隐藏用户输入(例如密码输入). 如果想使用非默认的掩码字符, 请在单词 Password 后加上此符号. 例如, <code>Password*</code> 将使用星号而不是黑色圆(项目符号) 作为掩码符号. 注意: 此选项对于多行编辑控件没有效果.</p>
<p><strong>ReadOnly</strong>: 阻止用户改变控件的内容. 不过, 仍然可以滚动, 选择文本或将文本复制到剪贴板.</p>
<p><strong>Tn</strong>: 字母 T 可以用来设置<a href="#EditMulti">多行编辑控件</a>的制表位(因为制表位决定了原义的 TAB 字符跳转的列位置, 所以它们可以把文本格式成列). 如果没有使用字母 T, 则每 32 个对话框单位设置一次制表位(每个 &quot;对话框单位&quot; 由操作系统决定). 如果仅使用一次字母 T, 则每 <strong>n</strong> 个单位设置一次横跨整个控件宽度的制表位. 例如, <code>MyGui.Add("Edit", "vMyEdit r16 t64")</code> 将设置制表位之间的距离为默认的两倍. 要自定义制表位, 请指定字母 T 多次, 如下例所示: <code>MyGui.Add("Edit", "vMyEdit r16 t8 t16 t32 t64 t128")</code>. 在列表中每个绝对的列位置设置一个制表位, 制表位数目最大可达 50 个. 注意: 制表位仅用于多行编辑控件.</p>
<p><strong>Uppercase</strong>: 将用户输入的字符自动转换成大写形式.</p>
<p><strong>WantCtrlA</strong>: 指定 <code>-WantCtrlA</code>(负 WantCtrlA) 来阻止用户按下 <kbd>Control</kbd>+<kbd>A</kbd> 来选择编辑控件中所有文本.</p>
<p id="WantReturn"><strong>WantReturn</strong>: 指定 <code>-WantReturn</code>(负 WantReturn) 来阻止多行编辑控件捕获 <kbd>Enter</kbd> 键. 按下 <kbd>Enter</kbd> 键相当于点击了窗口的<a href="#DefaultButton">默认按钮</a>(如果有). 在这种情况下, 用户可以使用 <kbd>Control</kbd>+<kbd>Enter</kbd> 来开始新行.</p>
<p><strong>WantTab</strong>: 使得 <kbd>Tab</kbd> 键击产生制表符而不是导航到下一个控件. 如果没有这个选项, 则在多行编辑控件中用户可以按下 <kbd>Control</kbd>+<kbd>Tab</kbd> 来产生制表符. 注意: <em>WantTab</em> 也可以用于单行编辑控件.</p>
<p><strong>Wrap</strong>: 指定 <code>-Wrap</code>(负 Wrap) 来关闭多行编辑控件中的自动换行属性. 由于在控件创建后不能改变此样式, 所以需要使用下列方法中的一个来改变它:: 1) <a href="../objects/Gui.htm#Destroy">Destroy</a> 后重新创建窗口和其中的控件; 或 2) 创建两个重叠的编辑控件, 其中一个启用自动换行而另一个禁用. 当前没有使用的那个可以保持空的和/或隐藏.</p>
<p>请参阅<a href="../objects/Gui.htm#OtherOptions">常规选项</a>来了解其他选项, 例如 <em>Right</em>, <em>Center</em> 和 <em>Hidden</em>. 另请参阅: <a href="../objects/Gui.htm#PosSize">控件的位置和大小</a>.</p>
<p><strong>更强大的编辑控件</strong>: HiEdit 是免费, 多选项卡, 支持大文件且消耗很少内存的编辑控件. 它可以编辑文本和二进制文件. 有关详情和演示, 请参阅 <a href="https://github.com/majkinetor/mm-autohotkey/tree/master/HiEdit">HiEdit on GitHub</a>.</p>

<h2 id="UpDown">UpDown</h2>
<p>描述: A pair of arrow buttons that the user can click to increase or decrease a value. By default, an UpDown control automatically snaps onto the previously added control. This previous control is known as the UpDown's <em>buddy control</em>. The most common example is a &quot;spinner&quot;, which is an UpDown attached to an <a href="#Edit">Edit control</a>.</p>
<p>例如:</p>
<pre>MyGui.Add("Edit")
MyGui.Add("UpDown", "vMyUpDown Range1-10", 5)</pre>
<p>外观:</p>
<img src="../static/ctrl_updown.png" alt="UpDown" />
<p>In the example above, the Edit control is the UpDown's buddy control. Whenever the user presses one of the arrow buttons, the number in the Edit control is automatically increased or decreased.</p>
<p>An UpDown's buddy control can also be a <a href="#Text">Text control</a> or <a href="#ListBox">ListBox</a>. However, due to OS limitations, controls other than these (such as ComboBox and DropDownList) might not work properly with the <a href="../objects/GuiOnEvent.htm#Change">Change</a> event and other features.</p>
<p>Specify the UpDown's starting position as the last parameter (if omitted, it starts off at 0 or the number in the allowable range that is closest to 0).</p>
<p>When <a href="../objects/Gui.htm#Submit">MyGui.Submit</a> or <a href="../objects/GuiControl.htm#Value">GuiCtrl.Value</a> is used, the return value is the current numeric position of the UpDown. If the UpDown is attached to an Edit control and you do not wish to validate the user's input, it is best to use the UpDown's value rather than the Edit's. This is because the UpDown will always yield an in-range number, even when the user has typed something non-numeric or out-of-range in the Edit control. On a related note, numbers with more than three digits get a <a href="../misc/Styles.htm#UpDownSep">thousands separator</a> (such as comma) by default. These separators are returned by the Edit control but not by the UpDown control.</p>
<p>Whenever the user clicks one of the arrow buttons or presses an arrow key on the keyboard, the <a href="../objects/GuiOnEvent.htm#Change">Change</a> event is raised.</p>

<h3>UpDown Options</h3>
<p id="Horz"><strong>Horz</strong>: Make's the control's buttons point left/right rather than up/down. By default, <em>Horz</em> also makes the control isolated (no buddy). This can be overridden by specifying <code>Horz 16</code> in the control's options.</p>
<p><strong>Left</strong>: Puts the UpDown on the left side of its buddy rather than the right.</p>
<p><strong>Range</strong>: Sets the range to be something other than 0 to 100. After the word Range, specify the minimum, a dash, and maximum. 例如, <code>Range1-1000</code> would allow a number between 1 and 1000 to be selected; <code>Range-50-50</code> would allow a number between -50 and 50; and <code>Range-10--5</code> would allow a number between -10 and -5. The minimum and maximum may be swapped to cause the arrows to move in the opposite of their normal direction. The broadest allowable range is -2147483648-2147483647. Finally, if the buddy control is a <a href="#ListBox">ListBox</a>, the range defaults to 32767-0 for verticals and the inverse for horizontals (<a href="#Horz">Horz</a>).</p>
<p><strong>Wrap</strong>: Causes the control to wrap around to the other end of its range when the user attempts to go beyond the minimum or maximum. Without <em>Wrap</em>, the control stops when the minimum or maximum is reached.</p>
<p><strong>-16</strong> (minus 16): Causes a vertical UpDown to be isolated; that is, it will have no buddy. This also causes the control to obey any specified width, height, and position rather than conforming to the size of its buddy control. In addition, an isolated UpDown tracks its own position internally. This position can be retrieved normally by means such as <a href="../objects/Gui.htm#Submit">MyGui.Submit</a>.</p>
<p id="UpDownSep"><strong>0x80</strong>: Include <code>0x80</code> in <em>Options</em> to omit the thousands separator that is normally present between every three decimal digits in the buddy control. However, this style is normally not used because the separators are omitted from the number whenever the script retrieves it from the UpDown control itself (rather than its buddy control).</p>
<p><strong>Increments other than 1</strong>: In <a href="http://numeric.nerim.net/AutoHotkey/Scripts/UpDown%20-%20Non-unitary%20increments.ahk">this script</a>, NumEric demonstrates how to change an UpDown's increment to a value other than 1 (such as 5 or 0.1).</p>
<p>See also: <a href="../objects/Gui.htm#PosSize">position and sizing of controls</a>.</p>

<span id="Pic"></span><h2 id="Picture">Picture (or Pic)</h2>
<p>Description: An area containing an image (see last two paragraphs for supported file types). The last parameter is the filename of the image, which is assumed to be in <a href="../Variables.htm#WorkingDir">A_WorkingDir</a> if an absolute path isn't specified.</p>
<p>例如:</p>
<pre>MyGui.Add("Picture", "w300 h-1", "C:\My Pictures\Company Logo.gif")</pre>
<p>To retain the image's actual width and/or height, omit the W and/or H options. Otherwise, the image is scaled to the specified width and/or height (this width and height also determines which icon to load from a multi-icon .ICO file). To shrink or enlarge the image while preserving its aspect ratio, specify -1 for one of the dimensions and a positive number for the other. 例如, specifying <code>w200 h-1</code> would make the image 200 pixels wide and cause its height to be set automatically. If the picture cannot be loaded or displayed (e.g. file not found), the control is left empty and its width and height are set to zero.</p>
<p>Picture controls support the <a href="../objects/GuiOnEvent.htm#Click">Click</a> and <a href="../objects/GuiOnEvent.htm#DoubleClick">DoubleClick</a> events, with the same <a href="#SS_NOTIFY">caveat</a> as Text controls.</p>
<p>To use a picture as a background for other controls, the picture should normally be added prior to those controls. However, if those controls are input-capable and the picture has the <a href="#SS_NOTIFY">SS_NOTIFY style</a> (which may be added automatically by <a href="../objects/GuiOnEvent.htm">OnEvent</a>), create the picture after the other controls and include <code>0x4000000</code> (which is WS_CLIPSIBLINGS) in the picture's <em>Options</em>. This trick also allows a picture to be the background behind a <a href="#Tab">Tab control</a> or <a href="ListView.htm">ListView</a>.</p>
<p id="IconSupport"><strong>Icons, cursors, and animated cursors</strong>: Icons and cursors may be loaded from the following types of files: ICO, CUR, ANI, EXE, DLL, CPL, SCR, and other types that contain icon resources. To use an icon group other than the first one in the file, include in <em>Options</em> the word Icon followed by the number of the group. In the following example, the default icon from the second icon group would be used: <code>MyGui.Add("Picture", "Icon2", "C:\My Application.exe")</code>.</p>
<p id="PicAltSubmit">Specifying the word AltSubmit in <em>Options</em> tells the program to use Microsoft's GDIPlus.dll to load the image, which might result in a different appearance for GIF, BMP, and icon images. For example, it would load a GIF that has a transparent background as a transparent bitmap, which allows the <a href="../objects/Gui.htm#BackgroundTrans">BackgroundTrans</a> option to take effect (but icons support transparency without AltSubmit).</p>
<p>Formats supported without the use of GDIPlus include GIF, JPG, BMP, ICO, CUR, and ANI images. GDIPlus is used by default for other image formats, such as PNG, TIF, Exif, WMF and EMF.</p>
<p><strong>Animated GIFs</strong>: Although animated GIF files can be displayed in a picture control, they will not actually be animated. To solve this, use the AniGIF DLL (which is free for non-commercial use) as demonstrated at the <a href="https://www.autohotkey.com/boards/viewtopic.php?t=6457">AutoHotkey Forums</a>. Alternatively, the <a href="#ActiveX">ActiveX</a> control type can be used. 例如:</p>
<pre><em>; Specify below the path to the GIF file to animate (local files are allowed too):</em>
pic := "http://www.animatedgif.net/cartoons/A_5odie_e0.gif"
MyGui := Gui.New()
MyGui.Add("ActiveX", "w100 h150", "mshtml:&lt;img src='" pic "' /&gt;")
MyGui.Show</pre>
<p>A <a href="../misc/ImageHandles.htm">bitmap or icon handle</a> can be used instead of a filename. 例如, <code>"HBITMAP:" handle</code>.</p>

<h2 id="Button">Button</h2>
<p>Description: A pushbutton, which can be pressed to trigger an action.  In this case, the last parameter is the name of the button (shown on the button itself), which may include linefeeds (`n) to start new lines.</p>
<p>例如:</p>
<pre>MyBtn := MyGui.Add("Button", "Default w80", "OK")
MyBtn.OnEvent("Click", "MyBtn_Click")  <em>; Call MyBtn_Click when clicked.</em>
</pre>
<p>外观:</p>
<img src="../static/ctrl_button.png" alt="Button" />
<p>The <a href="../objects/GuiOnEvent.htm#Click">Click</a> event is raised whenever the user clicks the button or presses <kbd>Space</kbd> or <kbd>Enter</kbd> while it has the focus.</p>
<p>The <a href="../objects/GuiOnEvent.htm#DoubleClick">DoubleClick</a>, <a href="../objects/GuiOnEvent.htm#Focus">Focus</a> and <a href="../objects/GuiOnEvent.htm#LoseFocus">LoseFocus</a> events are also supported. As these events are only raised if the control has the BS_NOTIFY (0x4000) style, it is added automatically by <a href="../objects/GuiOnEvent.htm">OnEvent</a>.</p>
<p id="DefaultButton">The example above includes the word <strong>Default</strong> in its <em>Options</em> to make "OK" the default button. The default button's <a href="../objects/GuiOnEvent.htm#Click">Click event</a> is automatically triggered whenever the user presses <kbd>Enter</kbd>, except when the keyboard focus is on a different button or a multi-line edit control having the <a href="#WantReturn">WantReturn</a> style. To later change the default button to another button, follow this example, which makes the Cancel button become the default: <code>MyGui["Cancel"].<a href="../objects/GuiControl.htm#Opt">Opt</a>("+Default")</code>. To later change the window to have no default button, follow this example: <code>MyGui["OK"].Opt("-Default")</code>.</p>
<p>An ampersand (&amp;) may be used in the button name to underline one of its letters. 例如:</p>
<pre>MyGui.Add("Button",, "&amp;Pause")</pre>
<p>In the example above, the letter P will be underlined, which allows the user to press <kbd>Alt</kbd>+<kbd>P</kbd> as <a href="../objects/Gui.htm#ShortcutKey">shortcut key</a>. To display a literal ampersand, specify two consecutive ampersands (&amp;&amp;).</p>

<p>Known limitation: Certain desktop themes might not display a button's text properly. If this occurs, try including <code>-Wrap</code> (minus Wrap) in the control's options. However, this also prevents having more than one line of text.</p>

<h2 id="Checkbox">Checkbox</h2>
<p>Description: A small box that can be checked or unchecked to represent On/Off, Yes/No, etc.</p>
<p>例如:</p>
<pre>MyGui.Add("CheckBox", "vShipToBillingAddress", "Ship to billing address?")</pre>
<p>外观:</p>
<img src="../static/ctrl_check.png" alt="Checkbox" />
<p>The last parameter is a label displayed next to the box, which is typically used as a prompt or description of what the checkbox does. It may include linefeeds (`n) to start new lines. If a width (W) is specified in <em>Options</em> but no <a href="../objects/Gui.htm#R">rows (R)</a> or height (H), the control's text will be word-wrapped as needed, and the control's height will be set automatically.</p>
<p><a href="../objects/GuiControl.htm#Value">GuiCtrl.Value</a> returns the number 1 for checked, 0 for unchecked, and -1 for gray/indeterminate.</p>
<p>Specify the word <strong>Check3</strong> in <em>Options</em> to enable a third "indeterminate" state that displays a gray checkmark or a square instead of a black checkmark (the indeterminate state indicates that the checkbox is neither checked nor unchecked). Specify the word <strong>Checked</strong> or <strong>CheckedGray</strong> in <em>Options</em> to have the checkbox start off checked or indeterminate, respectively. The word Checked may optionally be followed immediately by a 0, 1, or -1 to indicate the starting state. In other words, <code>"Checked"</code> and <code>"Checked" VarContainingOne</code> are the same.</p>
<p>Whenever the checkbox is clicked, it automatically cycles between its two or three possible states, and then raises the <a href="../objects/GuiOnEvent.htm#Click">Click</a> event, allowing the script to immediately respond to the user's input.</p>
<p>The <a href="../objects/GuiOnEvent.htm#DoubleClick">DoubleClick</a>, <a href="../objects/GuiOnEvent.htm#Focus">Focus</a> and <a href="../objects/GuiOnEvent.htm#LoseFocus">LoseFocus</a> events are also supported. As these events are only raised if the control has the BS_NOTIFY (0x4000) style, it is added automatically by <a href="../objects/GuiOnEvent.htm">OnEvent</a>. This style is not applied by default as it prevents rapid clicks from changing the state of the checkmark (such as if the user clicks twice to toggle from unchecked to checked and then to indeterminate).</p>
<p>Known limitation: Certain desktop themes might not display a checkbox's text properly. If this occurs, try including <code>-Wrap</code> (minus Wrap) in the control's options. However, this also prevents having more than one line of text.</p>

<h2 id="Radio">Radio</h2>
<p>Description: A radio button is a small empty circle that can be checked (on) or unchecked (off).</p>
<p>例如:</p>
<pre>MyGui.Add("Radio", "vMyRadioGroup", "Wait for all items to be in stock before shipping.")</pre>
<p>外观:</p>
<img src="../static/ctrl_radio.png" alt="Radio" />
<p>These controls usually appear in <em>radio groups</em>, each of which contains two or more radio buttons. When the user clicks a radio button to turn it on, any others in its radio group are turned off automatically (the user may also navigate inside a group with the arrow keys). A radio group is created automatically around all consecutively added radio buttons. To start a new group, specify the word <strong>Group</strong> in the <em>Options</em> of the first button of the new group -- or simply add a non-radio control in between, since that automatically starts a new group.</p>
<p>For the last parameter, specify the label to display to the right of the radio button. This label is typically used as a prompt or description, and it may include linefeeds (`n) to start new lines. If a width (W) is specified in <em>Options</em> but no rows (R) or height (H), the control's text will be word-wrapped as needed, and the control's height will be set automatically.</p>
<p>Specify the word <strong>Checked</strong> in <em>Options</em> to have the button start off in the &quot;on&quot; state. The word Checked may optionally be followed immediately by a 0 or 1 to indicate the starting state: 0 for unchecked and 1 for checked. In other words, <code>"Checked"</code> and <code>"Checked" VarContainingOne</code> are the same.</p>
<p><a href="../objects/GuiControl.htm#Value">GuiCtrl.Value</a> returns the number 1 for &quot;on&quot; and 0 for &quot;off&quot;. To instead retrieve the position number of the selected radio option within a radio group, <a href="../objects/GuiControl.htm#Name">name</a> only one of the radio buttons and use <a href="../objects/Gui.htm#submit-radio">MyGui.Submit</a>.</p>
<p>The <a href="../objects/GuiOnEvent.htm#Click">Click</a> event is raised whenever the user turns on the button. Unlike the single-variable mode in the previous paragraph, the event callback must be registered for each button in a radio group for which it should be called. This allows the flexibility to ignore the clicks of certain buttons. </p>
<p>The <a href="../objects/GuiOnEvent.htm#DoubleClick">DoubleClick</a>, <a href="../objects/GuiOnEvent.htm#Focus">Focus</a> and <a href="../objects/GuiOnEvent.htm#LoseFocus">LoseFocus</a> events are also supported. As these events are only raised if the control has the BS_NOTIFY (0x4000) style, it is added automatically by <a href="../objects/GuiOnEvent.htm">OnEvent</a>.</p>
<p>Known limitation: Certain desktop themes might not display a radio button's text properly. If this occurs, try including <code>-Wrap</code> (minus Wrap) in the control's options. However, this also prevents having more than one line of text.</p>

<span id="DDL"></span><h2 id="DropDownList">DropDownList (or DDL)</h2>
<p>Description: A list of choices that is displayed in response to pressing a small button.  In this case, the last parameter of <a href="../objects/Gui.htm#Add">MyGui.Add</a> is an <a href="../objects/Array.htm">Array</a> like <code>["Choice1","Choice2","Choice3"]</code>.</p>
<p>例如:</p>
<pre>MyGui.Add("DropDownList", "vColorChoice", ["Black","White","Red","Green","Blue"])
</pre>
<p>外观:</p>
<img src="../static/ctrl_ddl.png" alt="DDL" />
<p>To have one of the items pre-selected when the window first appears, include in <em>Options</em> the word <strong>Choose</strong> followed immediately by the number of an item to be pre-selected. For example, <code>Choose5</code> would pre-select the fifth item (as with other options, it can also be a variable such as <code>"Choose" Var</code>). After the control is created, use <a href="../objects/GuiControl.htm#Value">GuiCtrl.Value</a>, <a href="../objects/GuiControl.htm#Text">GuiCtrl.Text</a> or <a href="../objects/GuiControl.htm#Choose">GuiCtrl.Choose</a> to change the selection, and <a href="../objects/GuiControl.htm#Add">GuiCtrl.Add</a> or <a href="../objects/GuiControl.htm#Delete">GuiCtrl.Delete</a> to add or remove entries from the list.</p>
<p>Specify either the word <strong>Uppercase</strong> or <strong>Lowercase</strong> in <em>Options</em> to automatically convert all items in the list to uppercase or lowercase. Specify the word <strong>Sort</strong> to automatically sort the contents of the list alphabetically (this also affects any items  added later via <a href="../objects/GuiControl.htm#Add">GuiCtrl.Add</a>). The Sort option also enables incremental searching whenever the list is dropped down; this allows an item to be selected by typing the first few characters of its name.</p>
<p>When <a href="../objects/Gui.htm#Submit">MyGui.Submit</a> or <a href="../objects/GuiControl.htm#Value">GuiCtrl.Value</a> is used, the return value is the position number of the currently selected item (the first item is 1, the second is 2, etc.) or zero if none is selected. To get its text instead, use <a href="../objects/GuiControl.htm#Text">GuiCtrl.Text</a>.</p>
<p>Whenever the user selects a new item, the <a href="../objects/GuiOnEvent.htm#Change">Change</a> event is raised. The <a href="../objects/GuiOnEvent.htm#Focus">Focus</a> and <a href="../objects/GuiOnEvent.htm#LoseFocus">LoseFocus</a> events are also supported.</p>
<p>Use the <a href="../objects/Gui.htm#R">R or H option</a> to control the height of the popup list. 例如, specifying <code>R5</code> would make the list 5 rows tall, while <code>H400</code> would set the total height of the selection field and list to 400 pixels. If both R and H are omitted, the list will automatically expand to take advantage of the available height of the user's desktop.</p>
<p id="ComboBoxHeight">To set the height of the selection field or list items, use the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb775911">CB_SETITEMHEIGHT</a> message as in the example below:</p>
<pre>MyGui := Gui.New()
DDL := MyGui.Add("DDL", "vcbx w200 Choose1", ["One","Two"])
<em>; CB_SETITEMHEIGHT = 0x153</em>
PostMessage(0x153, -1, 50, DDL)  <em>; Set height of selection field.</em>
PostMessage(0x153, 0, 50, DDL)  <em>; Set height of list items.</em>
MyGui.Show("h70")</pre>

<h2 id="ComboBox">ComboBox</h2>
<p>Description: Same as DropDownList but also permits free-form text to be entered as an alternative to picking an item from the list.</p>
<p>例如:</p>
<pre>MyGui.Add("ComboBox", "vColorChoice", ["Red","Green","Blue","Black","White"])
</pre>
<p>外观:</p>
<img src="../static/ctrl_combo.png" alt="ComboBox" />
<p>In addition to allowing all the same options as DropDownList above, the word <strong>Limit</strong> may be included in <em>Options</em> to restrict the user's input to the visible width of the ComboBox's edit field. Also, the word <strong>Simple</strong> may be specified to make the ComboBox behave as though it is an Edit field with a ListBox beneath it.</p>
<p><a href="../objects/GuiControl.htm#Value">GuiCtrl.Value</a> returns the position number of the currently selected item (the first item is 1, the second is 2, etc.) or 0 if the control contains text which does not match a list item. To get the contents of the ComboBox's edit field, use <a href="../objects/GuiControl.htm#Text">GuiCtrl.Text</a>. <a href="../objects/Gui.htm#Submit">MyGui.Submit</a> stores the text, unless the word <strong>AltSubmit</strong> is in the control's <em>Options</em> and the text matches a list item, in which case it stores the position number of the item.</p>
<p>Whenever the user selects a new item or changes the control's text, the <a href="../objects/GuiOnEvent.htm#Change">Change</a> event is raised. The <a href="../objects/GuiOnEvent.htm#Focus">Focus</a> and <a href="../objects/GuiOnEvent.htm#LoseFocus">LoseFocus</a> events are also supported.</p>

<h2 id="ListBox">ListBox</h2>
<p>Description: A relatively tall box containing a list of choices that can be selected. In this case, the last parameter of <a href="../objects/Gui.htm#Add">MyGui.Add</a> is an <a href="../objects/Array.htm">Array</a> like <code>["Choice1","Choice2","Choice3"]</code>.</p>
<p>例如:</p>
<pre>MyGui.Add("ListBox", "r5 vColorChoice", ["Red","Green","Blue","Black","White"])
</pre>
<p>外观:</p>
<img src="../static/ctrl_list.png" alt="ListBox" />
<p id="ChooseLB">To have one of the items pre-selected when the window first appears, include in <em>Options</em> the word <strong>Choose</strong> followed immediately by the number of an item to be pre-selected. For example, <code>Choose5</code> would pre-select the fifth item. To have multiple items pre-selected, use <a href="../objects/GuiControl.htm#Choose">GuiCtrl.Choose</a> multiple times (requires the <a href="#ListBoxMulti">Multi</a> option). After the control is created, use <a href="../objects/GuiControl.htm#Value">GuiCtrl.Value</a>, <a href="../objects/GuiControl.htm#Text">GuiCtrl.Text</a> or <a href="../objects/GuiControl.htm#Choose">GuiCtrl.Choose</a> to change the selection, and <a href="../objects/GuiControl.htm#Add">GuiCtrl.Add</a> or <a href="../objects/GuiControl.htm#Delete">GuiCtrl.Delete</a> to add or remove entries from the list.</p>
<p>If the <a href="#ListBoxMulti">Multi</a> option is absent, <a href="../objects/GuiControl.htm#Value">GuiCtrl.Value</a> returns the position number of the currently selected item (the first item is 1, the second is 2, etc.) or 0 if there is no item selected. To get the selected item's text instead, use <a href="../objects/GuiControl.htm#Text">GuiCtrl.Text</a>. If the <a href="#ListBoxMulti">Multi</a> option is used, <a href="../objects/GuiControl.htm#Value">GuiCtrl.Value</a> and <a href="../objects/GuiControl.htm#Text">GuiCtrl.Text</a> return an array of items instead of a single item.</p>
<p><a href="../objects/Gui.htm#Submit">MyGui.Submit</a> stores <a href="../objects/GuiControl.htm#Text">GuiCtrl.Text</a> by default, but stores <a href="../objects/GuiControl.htm#Value">GuiCtrl.Value</a> instead if the word <strong>AltSubmit</strong> is in the control's <em>Options</em>.</p>
<p>Whenever the user selects or deselects one or more items, the <a href="../objects/GuiOnEvent.htm#Change">Change</a> event is raised. The <a href="../objects/GuiOnEvent.htm#DoubleClick">DoubleClick</a>, <a href="../objects/GuiOnEvent.htm#Focus">Focus</a> and <a href="../objects/GuiOnEvent.htm#LoseFocus">LoseFocus</a> events are also supported.</p>
<p id="LBRedraw">When adding a large number of items to a ListBox, performance may be improved by using <code>MyListBox.Opt("-Redraw")</code> prior to the operation, and <code>MyListBox.Opt("+Redraw")</code> afterward.</p>

<h3>ListBox Options</h3>
<p><strong>Choose</strong>: See <a href="#ChooseLB">above</a>.</p>
<p id="ListBoxMulti"><strong>Multi</strong>: Allows more than one item to be selected simultaneously via shift-click and control-click (to avoid the need for shift/control-click, specify <a href="../misc/Styles.htm#LBS_MULTIPLESEL">the number 8</a> instead of the word Multi). In this case, <a href="../objects/Gui.htm#Submit">MyGui.Submit</a> or <a href="../objects/GuiControl.htm#Value">GuiCtrl.Value</a> returns an array of selected position numbers. 例如, <code>[1, 2, 3]</code> would indicate that the first three items are selected. To get an array of selected texts instead, use <a href="../objects/GuiControl.htm#Text">GuiCtrl.Text</a>. To extract the individual items from the array, use <code>MyListBox.Text[1]</code> (1 would be the first item) or a <a href="For.htm">For-loop</a> such as this example:</p>
<pre>For Index, Field in MyListBox.Text
{
    MsgBox "Selection number " Index " is " Field
}</pre>
<p><strong>ReadOnly</strong>: Prevents items from being visibly highlighted when they are selected (but <a href="../objects/Gui.htm#Submit">MyGui.Submit</a>, <a href="../objects/GuiControl.htm#Value">GuiCtrl.Value</a> or <a href="../objects/GuiControl.htm#Text">GuiCtrl.Text</a> will still return the selected item).</p>
<p><strong>Sort</strong>: Automatically sorts the contents of the list alphabetically (this also affects any items added later via <a href="../objects/GuiControl.htm#Add">GuiCtrl.Add</a>). The Sort option also enables incremental searching, which allows an item to be selected by typing the first few characters of its name.</p>
<p><strong>Tn</strong>: The letter T may be used to set tab stops, which can be used to format the text into columns. If the letter T is not used, tab stops are set at every 32 dialog units (the width of each &quot;dialog unit&quot; is determined by the operating system). If the letter T is used only once, tab stops are set at every <strong>n</strong> units across the entire width of the control. 例如, <code>MyGui.Add("ListBox", "vMyListBox t64")</code> would double the default distance between tab stops. To have custom tab stops, specify the letter T multiple times as in the following example: <code>MyGui.Add("ListBox", "vMyListBox t8 t16 t32 t64 t128")</code>. One tab stop is set for each of the absolute column positions in the list, up to a maximum of 50 tab stops.</p>
<p><strong>0x100</strong>: Include 0x100 in <em>Options</em> to turn on the LBS_NOINTEGRALHEIGHT style. This forces the ListBox to be exactly the height specified rather than a height that prevents a partial row from appearing at the bottom. This option also prevents the ListBox from shrinking when its font is changed.</p>
<p>To specify the number of rows of text (or the height and width), 请参阅 <a href="../objects/Gui.htm#PosSize">position and sizing of controls</a>.</p>

<h2>ListView and TreeView</h2>
<p>See separate pages <a href="ListView.htm">ListView</a> and <a href="TreeView.htm">TreeView</a>.</p>

<h2 id="Link">Link</h2>
<p>Description: A text control that can contain links similar to those found in a web browser. Within the control's text, enclose the link text within <code>&lt;A&gt;</code> and <code>&lt;/A&gt;</code> to create a clickable link. Although this looks like HTML, Link controls only support the opening <code>&lt;A&gt;</code> tag (optionally with an ID and/or HREF attribute) and closing <code>&lt;/A&gt;</code> tag.</p>
<p>例如:</p>
<pre>MyGui.Add("Link",, 'This is a &lt;a href="https://www.autohotkey.com"&gt;link&lt;/a&gt;')
MyGui.Add("Link",, 'Links may be used anywhere in the text like &lt;a id="A"&gt;this&lt;/a&gt; or &lt;a id="B"&gt;that&lt;/a&gt;')</pre>
<p>外观:</p>
<img src="../static/ctrl_link.png" alt="Link" />

<p>Whenever the user clicks on a link, the <a href="../objects/GuiOnEvent.htm#Click">Click</a> event is raised. If the control has no Click callback (registered by calling <a href="../objects/GuiOnEvent.htm">OnEvent</a>), the link's HREF is automatically executed as though passed to the <a href="Run.htm">Run</a> function.</p>
<pre>Gui := Gui.New()
Link := MyGui.Add("Link",
    , 'Click to run &lt;a href="notepad" id="notepad"&gt;Notepad&lt;/a&gt; or open '
    . '&lt;a id="help" href="https://www.autohotkey.com/docs/"&gt;online help&lt;/a&gt;.')
Link.OnEvent("Click", "Link_Click")
Link_Click(Ctrl, ID, HREF)
{
    if MsgBox("ID: " ID "`nHREF: " HREF "`n`nExecute this link?",, "y/n") = "yes"
        Run(HREF)
}
MyGui.Show()</pre>

<h2 id="Hotkey">Hotkey</h2>
<p>Description: A box that looks like a single-line edit control but instead accepts a keyboard combination pressed by the user. 例如, if the user presses <kbd>Control</kbd>+<kbd>Alt</kbd>+<kbd>C</kbd> on an English keyboard layout, the box would display &quot;Ctrl + Alt + C&quot;.</p>
<p>例如:</p>
<pre>MyGui.Add("Hotkey", "vChosenHotkey")</pre>
<p>外观:</p>
<img src="../static/ctrl_hotkey.png" alt="Hotkey" />
<p><a href="../objects/GuiControl.htm#Value">GuiCtrl.Value</a> returns the control's hotkey modifiers and name, which are compatible with the <a href="Hotkey.htm">Hotkey</a> function. Examples: <code>^!C</code>, <code>+!Home</code>, <code>+^Down</code>, <code>^Numpad1</code>, <code>!NumpadEnd</code>. If there is no hotkey in the control, the value is blank.</p>
<p class="note"><strong>Note</strong>: Some keys are displayed the same even though they are retrieved as different names. 例如, both <code>^Numpad7</code> and <code>^NumpadHome</code> might be displayed as Ctrl + Num 7.</p>
<p>By default, the control starts off with no hotkey specified. To instead have a default, specify its modifiers and name as the last parameter as in this example: <code>MyGui.Add("Hotkey", "vChosenHotkey", "^!p")</code><br>
The only modifiers supported are ^ (Control), ! (Alt), and + (Shift). See the <a href="../KeyList.htm">key list</a> for available key names.</p>
<p>Whenever the user changes the control's content (by pressing a key), the <a href="../objects/GuiOnEvent.htm#Change">Change</a> event is raised.</p>
<p class="note"><strong>Note</strong>: The event is raised even when an incomplete hotkey is present. 例如, if the user holds down the <kbd>Control</kbd> key, the event is raised once and <a href="../objects/GuiControl.htm#Value">Value</a> returns only a circumflex (^). When the user completes the hotkey, the event is raised again and <a href="../objects/GuiControl.htm#Value">Value</a> returns the complete hotkey.</p>
<p>要限制用户可以使用的热键类型, 请在选项中包含单词 <strong>Limit</strong> 接着一个或多个下列数字的和:</p>
<ul>
  <li>1: 阻止不带有修饰符的按键</li>
  <li>2: 仅阻止 <kbd>Shift</kbd></li>
  <li>4: 仅阻止 <kbd>Control</kbd></li>
  <li>8: 仅阻止 <kbd>Alt</kbd></li>
  <li>16: 阻止 <kbd>Shift</kbd>+<kbd>Control</kbd></li>
  <li>32: 阻止 <kbd>Shift</kbd>+<kbd>Alt</kbd></li>
  <li>64: 不支持这个值(它不会正确执行).</li>
  <li>128: 阻止 <kbd>Shift</kbd>+<kbd>Control</kbd>+<kbd>Alt</kbd>.</li>
</ul>
<p>例如, <code>Limit1</code> 将阻止输入不带修饰符的热键(例如单独的字母和数字), 而 <code>Limit15</code> 则要求至少有两个修饰键. 如果用户输入了被禁止的修饰键组合, 则自动使用  <kbd>Control</kbd>+<kbd>Alt</kbd> 组合代替.</p>
<p>The Hotkey control has limited capabilities. 例如, it does not support mouse/joystick hotkeys or the <kbd>Win</kbd> key (LWin and RWin). One way to work around this is to provide one or more <a href="#Checkbox">checkboxes</a> as a means for the user to enable extra modifiers such as the <kbd>Win</kbd> key.</p>

<h2 id="DateTime">DateTime</h2>
<p>Description: A box that looks like a single-line edit control but instead accepts a date and/or time. A drop-down calendar is also provided.</p>
<p>例如:</p>
<pre>MyGui.Add("DateTime", "vMyDateTime", "LongDate")
</pre>
<p>外观:</p>
<img src="../static/ctrl_datetime.png" alt="DateTime" />
<p>The last parameter is a format string, as described below.</p>
<div class="methodShort" id="DateTimeFormat">
<h3>SetFormat</h3>
<p>Sets the display format of a DateTime control.</p>
<pre class="Syntax">DateTime.<span class="func">SetFormat</span>(<span class="optional">Format</span>)</pre>
<dl><dt>Format</dt><dd>
<p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
<p>One of the following:</p>
<p><strong>ShortDate</strong> (or omitted/blank): Uses the locale's short date format. 例如, in some locales it would look like: 6/1/2005</p>
<p><strong>LongDate</strong>: Uses the locale's long date format. 例如, in some locales it would look like: Wednesday, June 01, 2005</p>
<p><strong>Time</strong>: Shows only the time using the locale's time format. Although the date is not shown, it is still present in the control and will be retrieved along with the time in the <a href="FileSetTime.htm#YYYYMMDD">YYYYMMDDHH24MISS</a> format. For example, in some locales it would look like: 9:37:45 PM</p>
<p><strong>(custom format)</strong>: Specify any combination of <a href="FormatTime.htm">date and time formats</a>. 例如, <code>"M/d/yy HH:mm"</code> would look like 6/1/05 21:37. Similarly, <code>"dddd MMMM d, yyyy hh:mm:ss tt"</code> would look like Wednesday June 1, 2005 09:37:45 PM. Letters and numbers to be displayed literally should be enclosed in single quotes as in this example: <code>"'Date:' MM/dd/yy 'Time:' hh:mm:ss tt"</code>. By contrast, non-alphanumeric characters such as spaces, tabs, slashes, colons, commas, and other punctuation do not need to be enclosed in single quotes. The exception to this is the single quote character itself: to produce it literally, use four consecutive single quotes (''''), or just two if the quote is already inside an outer pair of quotes.</p>
</dd></dl>
</div>

<h3>DateTime Usage</h3>
<p id="ChooseDT">To have a date other than today pre-selected, include in <em>Options</em> the word <strong>Choose</strong> followed immediately by a date in YYYYMMDD format. 例如, <code>Choose20050531</code> would pre-select May 31, 2005 (as with other options, it can also be a variable such as <code>"Choose" Var</code>). To have no date/time selected, specify <strong>ChooseNone</strong>. <em>ChooseNone</em> also creates a checkbox inside the control that is unchecked whenever the control has no date. Whenever the control has no date, <a href="../objects/Gui.htm#Submit">MyGui.Submit</a> or <a href="../objects/GuiControl.htm#Value">GuiCtrl.Value</a> will retrieve a blank value (empty string).</p>
<p>The time of day may optionally be present. However, it must always be preceded by a date when going into or coming out of the control. The format of the time portion is HH24MISS (hours, minutes, seconds), where HH24 is expressed in 24-hour format; 例如, 09 is 9am and 21 is 9pm. Thus, a complete date-time string would have the format <a href="FileSetTime.htm#YYYYMMDD">YYYYMMDDHH24MISS</a>.</p>
<p>当指定了 YYYYMMDDHH24MISS 格式的日期时, 只有前导部分是不能缺少的. 其他任何省略的元素将使用下列默认值代替: MM: 月份 01, DD: 日期 01, HH24: 小时 00, MI: 分钟 00, SS: 秒 00.</p>
<p>Within the drop-down calendar, the today-string at the bottom can be clicked to select today's date. In addition, the year and month name are clickable and allow easy navigation to a new month or year.</p>
<p id="DateTime_Keyboard_Navigation">键盘导航: 使用 <kbd>&uarr;</kbd>/<kbd>&darr;</kbd> 方向键, <kbd>+</kbd>/<kbd>-</kbd> 和 <kbd>Home</kbd>/<kbd>End</kbd> 来增加或减少控件的值. 使用 <kbd>&larr;</kbd> 和 <kbd>&rarr;</kbd> 方向键在控件中的区域间移动. 在下拉日历中, 使用方向键在日期间移动; 使用 <kbd>PageUp</kbd>/<kbd>PageDown</kbd> 在月份间往后/往前移动; 使用 <kbd>Home</kbd>/<kbd>End</kbd> 选择当月的第一天/最后一天.</p>
<p>When <a href="../objects/Gui.htm#Submit">MyGui.Submit</a> or <a href="../objects/GuiControl.htm#Value">GuiCtrl.Value</a> is used, the return value is the selected date and time in <a href="FileSetTime.htm#YYYYMMDD">YYYYMMDDHH24MISS</a> format. Both the date and the time are present regardless of whether they were actually visible in the control.</p>
<p>Whenever the user changes the date or time, the <a href="../objects/GuiOnEvent.htm#Change">Change</a> event is raised. The <a href="../objects/GuiOnEvent.htm#Focus">Focus</a> and <a href="../objects/GuiOnEvent.htm#LoseFocus">LoseFocus</a> events are also supported.</p>

<h3>DateTime Options</h3>
<p><strong>Choose</strong>: See <a href="#ChooseDT">above</a>.</p>
<p><strong>Range</strong>: Restricts how far back or forward in time the selected date can be. After the word Range, specify the minimum and maximum dates in YYYYMMDD format (with a dash between them). 例如, <code>Range20050101-20050615</code> would restrict the date to the first 5.5 months of 2005. Either the minimum or maximum may be omitted to leave the control unrestricted in that direction. 例如, <code>Range20010101</code> would prevent a date prior to 2001 from being selected and <code>Range-20091231</code> (leading dash) would prevent a date later than 2009 from being selected. Without the Range option, any date between the years 1601 and 9999 can be selected. The time of day cannot be restricted.</p>
<p><strong>Right</strong>: Causes the drop-down calendar to drop down on the right side of the control instead of the left.</p>
<p><strong>1</strong>: Specify the number 1 in <em>Options</em> to provide an up-down control to the right of the control to modify date-time values, which replaces the button of the drop-down month calendar that would otherwise be available. This does not work in conjunction with the format option LongDate described above.</p>
<p id="ChooseNone"><strong>2</strong>: Specify the number 2 in <em>Options</em> to provide a checkbox inside the control that the user may uncheck to indicate that no date/time is selected. Once the control is created, this option cannot be changed.</p>

<h2 id="MonthCal">MonthCal</h2>
<p>Description: A tall and wide control that displays all the days of the month in calendar format. The user may select a single date or a range of dates.</p>
<p>例如:</p>
<pre>MyGui.Add("MonthCal", "vMyCalendar")</pre>
<p>外观:</p>
<img src="../static/ctrl_monthcal.png" alt="MonthCal" />
<p>To have a date other than today pre-selected, specify it as the third parameter in YYYYMMDD format (e.g. <code>20050531</code>). A range of dates may also be pre-selected by including a dash between two dates (e.g. <code>"20050525-20050531"</code>).</p>
<p>It is usually best to omit width (W) and height (H) for a MonthCal because it automatically sizes itself to fit exactly one month. To display more than one month vertically, specify <code>R2</code> or higher in <em>Options</em>. To display more than one month horizontally, specify <code>W-2</code> (W negative two) or higher. These options may both be present to expand in both directions.</p>
<p>The today-string at the bottom of the control can be clicked to select today's date. In addition, the year and month name are clickable and allow easy selection of a new year or month.</p>
<p>键盘导航: 在 MonthCal 中完全支持键盘导航, 但只有当它具有键盘焦点时才支持. 有关支持的键盘快捷方式, 请参阅<a href="#DateTime_Keyboard_Navigation">DateTime 的键盘导航</a>(带有下拉日历).</p>
<p>When <a href="../objects/Gui.htm#Submit">MyGui.Submit</a> or <a href="../objects/GuiControl.htm#Value">GuiCtrl.Value</a> is used, the return value is the selected date in YYYYMMDD format (without any time portion). However, when the <a href="#MonthCalMulti">multi-select</a> option is in effect, the minimum and maximum dates are retrieved with a dash between them (e.g. <code>20050101-20050108</code>). If only a single date was selected in a multi-select calendar, the minimum and maximum are both present but identical. <a href="StrSplit.htm">StrSplit</a> can be used to separate the dates. 例如, the following would put the minimum in Date[1] and the maximum in Date[2]: <code>Date := StrSplit(MyMonthCal.Value, "-")</code>.</p>
<p>当用户更改选择时, 将引发<a href="../objects/GuiOnEvent.htm#Change">更改</a>事件.</p>
<p>When specifying dates in the YYYYMMDD format, the MM and/or DD portions may be omitted, in which case they are assumed to be 1. 例如, <code>200205</code> is seen as 20020501, and <code>2005</code> is seen as 20050101.</p>

<h3>MonthCal Options</h3>
<p id="MonthCalMulti"><strong>Multi</strong>: Multi-select. Allows the user to shift-click or click-drag to select a range of adjacent dates (the user may still select a single date too). This option may be specified explicitly or put into effect automatically by means of specifying a selection range when the control is created. 例如: <code>MyGui.Add("MonthCal", "vMyCal", "20050101-20050108")</code>. Once the control is created, this option cannot be changed.</p>
<p><strong>Range</strong>: Restricts how far back or forward in time the calendar can go. After the word Range, specify the minimum and maximum dates in YYYYMMDD format (with a dash between them). 例如, <code>Range20050101-20050615</code> would restrict the selection to the first 5.5 months of 2005. Either the minimum or maximum may be omitted to leave the calendar unrestricted in that direction. 例如, <code>Range20010101</code> would prevent a date prior to 2001 from being selected and <code>Range-20091231</code> (leading dash) would prevent a date later than 2009 from being selected. Without the Range option, any date between the years 1601 and 9999 can be selected.</p>
<p><strong>4</strong>: Specify the number 4 in <em>Options</em> to display week numbers (1-52) to the left of each row of days. Week 1 is defined as the first week that contains at least four days.</p>
<p><strong>8</strong>: Specify the number 8 in <em>Options</em> to prevent the circling of today's date within the control.</p>
<p><strong>16</strong>: Specify the number 16 in <em>Options</em> to prevent the display of today's date at the bottom of the control.</p>

<h2 id="Slider">Slider</h2>
<p>Description: A sliding bar that the user can move along a vertical or horizontal track. The standard volume control in the taskbar's tray is an example of a slider.</p>
<p>例如:</p>
<pre>MyGui.Add("Slider", "vMySlider", 50)</pre>
<p>外观:</p>
<img src="../static/ctrl_slider.png" alt="Slider" />
<p>Specify the starting position of the slider as the last parameter. If the last parameter  is omitted, the slider starts off at 0 or the number in the allowable range that is closest to 0.</p>
<p>The user may slide the control by the following means: 1) dragging the bar with the mouse; 2) clicking inside the bar's track area with the mouse; 3) turning the mouse wheel while the control has focus; or 4) pressing the following keys while the control has focus: <kbd>&uarr;</kbd>, <kbd>&rarr;</kbd>, <kbd>&darr;</kbd>, <kbd>&larr;</kbd>, <kbd>PageUp</kbd>, <kbd>PageDown</kbd>, <kbd>Home</kbd>, and <kbd>End</kbd>.</p>
<p><a href="../objects/GuiControl.htm#Value">GuiCtrl.Value</a> and <a href="../objects/Gui.htm#Submit">MyGui.Submit</a> return or store the current numeric position of the slider.</p>

<h3 id="slider-change">Detecting Changes</h3>
<p>By default, the slider's <a href="../objects/GuiOnEvent.htm#Change">Change</a> event is raised when the user has stopped moving the slider, such as by releasing the mouse button after having dragging it. If the control has the <strong>AltSubmit</strong> option, the Change event is also raised (very frequently) after each visible movement of the bar while the user is dragging it with the mouse.</p>
<pre class="Syntax">Ctrl_<span class="func">Change</span>(GuiCtrlObj, Info)</pre>
<dl>
  <dt>Info</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
    <p>A numeric value from the table below indicating how the slider was moved. These values and the corresponding names are defined in the Windows SDK.</p>
  </dd>
</dl>
<table class="info">
  <tr><th>Value</th><th>Name</th><th>Meaning</th></tr>
  <tr><td>0</td><td>TB_LINEUP</td><td>The user pressed the <kbd>&larr;</kbd> or <kbd>&uarr;</kbd> key.</td></tr>
  <tr><td>1</td><td>TB_LINEDOWN</td><td>The user pressed the <kbd>&rarr;</kbd> or <kbd>&darr;</kbd> key.</td></tr>
  <tr><td>2</td><td>TB_PAGEUP</td><td>The user pressed the <kbd>PageUp</kbd> key.</td></tr>
  <tr><td>3</td><td>TB_PAGEDOWN</td><td>The user pressed the <kbd>PageDown</kbd> key.</td></tr>
  <tr><td>4</td><td>TB_THUMBPOSITION</td><td>The user moved the slider via the mouse wheel, or finished a drag-and-drop to a new position.</td></tr>
  <tr><td>6</td><td>TB_TOP</td><td>The user pressed the <kbd>Home</kbd> key to send the slider to the left or top side. </td></tr>
  <tr><td>7</td><td>TB_BOTTOM</td><td>The user pressed the <kbd>End</kbd> key to send the slider to the right or bottom side. </td></tr>
  <tr><td colspan="3"><strong>Only if the AltSubmit option is used:</strong></td></tr>
  <tr><td>5</td><td>TB_THUMBTRACK</td><td>The user is currently dragging the slider via the mouse; that is, the mouse button is currently down.</td></tr>
  <tr><td>8</td><td>TB_ENDTRACK</td><td>The user has finished moving the slider, either via the mouse or the keyboard. Note: With the exception of mouse wheel movement (#4), the Change event is raised again for #8 even though it was already raised with one of the digits above.</td></tr>
</table>

<h3>Slider Options</h3>
<p><strong>Buddy1</strong> and <strong>Buddy2</strong>: Specifies up to two existing controls to automatically reposition at the ends of the slider. Buddy1 is displayed at the left or top side (depending on whether the Vertical option is present). Buddy2 is displayed at the right or bottom side. After the word Buddy1 or Buddy2, specify the <a href="../objects/GuiControl.htm#Name">Name</a> or <a href="../objects/GuiControl.htm#Hwnd">HWND</a> of an existing control. 例如, <code>Buddy1MyTopText</code> would assign the control whose name is MyTopText. The text or ClassNN of a control can also be used, but only up to the first space or tab.</p>
<p><strong>Center</strong>: The thumb (the bar moved by the user) will be blunt on both ends rather than pointed at one end.</p>
<p><strong>Invert</strong>: Reverses the control so that the lower value is considered to be on the right/bottom rather than the left/top. This is typically used to make a vertical slider move in the direction of a traditional volume control. Note: The ToolTip option described below will not obey the inversion and therefore should not be used in this case.</p>
<p><strong>Left</strong>: The thumb (the bar moved by the user) will point to the top rather than the bottom. But if the Vertical option is in effect, the thumb will point to the left rather than the right.</p>
<p><strong>Line</strong>: Specifies the number of positions to move when the user presses one of the arrow keys. After the word Line, specify number of positions to move. 例如: <code>Line2</code>.</p>
<p><strong>NoTicks</strong>: Omits tickmarks alongside the track.</p>
<p><strong>Page</strong>: Specifies the number of positions to move when the user presses the <kbd>PageUp</kbd> or <kbd>PageDown</kbd> key. After the word Page, specify number of positions to move. 例如: <code>Page10</code>.</p>
<p><strong>Range</strong>: Sets the range to be something other than 0 to 100. After the word Range, specify the minimum, a dash, and maximum. 例如, <code>Range1-1000</code> would allow a number between 1 and 1000 to be selected; <code>Range-50-50</code> would allow a number between -50 and 50; and <code>Range-10--5</code> would allow a number between -10 and -5.</p>
<p><strong>Thick</strong>: Specifies the length of the thumb (the bar moved by the user). After the word Thick, specify the thickness in pixels (e.g. <code>Thick30</code>). To go beyond a certain thickness, it is probably necessary to either specify the Center option or remove the theme from the control (which can be done by specifying <code>-Theme</code> in the control's options).</p>
<p><strong>TickInterval</strong>: Provides tickmarks alongside the track at the specified interval. After the word TickInterval, specify the interval at which to display additional tickmarks (if the interval is omitted, it is assumed to be 1). 例如, <code>TickInterval10</code> would display a tickmark once every 10 positions.</p>
<p><strong>ToolTip</strong>: Creates a tooltip that reports the numeric position of the slider as the user is dragging it. To have the tooltip appear in a non-default position, specify one of the following instead: <code>ToolTipLeft</code> or <code>ToolTipRight</code> (for vertical sliders); <code>ToolTipTop</code> or <code>ToolTipBottom</code> (for horizontal sliders).</p>
<p><strong>Vertical</strong>: Makes the control slide up and down rather than left and right.</p>
<p>The above options can be changed via <a href="../objects/GuiControl.htm#Opt">GuiCtrl.Opt</a> after the control is created.</p>

<h2 id="Progress">Progress</h2>
<p>Description: A dual-color bar typically used to indicate how much progress has been made toward the completion of an operation.</p>
<p>例如:</p>
<pre>MyGui.Add("Progress", "w200 h20 cBlue vMyProgress", 75)</pre>
<p>外观:</p>
<img src="../static/ctrl_progress.png" alt="Progress" />
<p>Specify the starting position of the bar as the third parameter (if omitted, the bar starts off at 0 or the number in the allowable range that is closest to 0). To later change the position of the bar, follow these examples, all of which operate upon a progress bar whose <a href="../objects/GuiControl.htm#Name">Name</a> is MyProgress:</p>
<pre>MyGui["MyProgress"].<a href="../objects/GuiControl.htm#Value">Value</a> += 20  <em>; Increase the current position by 20.</em>
MyGui["MyProgress"].Value := 50  <em>; Set the current position to 50.</em></pre>
<p>For horizontal Progress Bars, the thickness of the bar is equal to the control's height. For vertical Progress Bars it is equal to the control's width.</p>

<h3>Progress Options</h3>
<p><strong>Cn</strong>: Changes the bar's color. Specify for <strong>n</strong> one of the 16 primary HTML <a href="../misc/Colors.htm">color names</a> or a 6-digit RGB color value. Examples: <code>cRed</code>, <code>cFFFF33</code>, <code>cDefault</code>. If the C option is never used (or <code>cDefault</code> is specified), the system's default bar color will be used.</p>
<p><strong>BackgroundN</strong>: Changes the bar's background color. Specify for <strong>n</strong> one of the 16 primary HTML <a href="../misc/Colors.htm">color names</a> or a 6-digit RGB color value. Examples: <code>BackgroundGreen</code>, <code>BackgroundFFFF33</code>, <code>BackgroundDefault</code>. If the Background option is never used (or <code>BackgroundDefault</code> is specified), the background color will be that of the window or <a href="#Tab">tab control</a> behind it.</p>
<p><strong>Range</strong>: Sets the range to be something other than 0 to 100. After the word Range, specify the minimum, a dash, and maximum. 例如, <code>Range0-1000</code> would allow numbers between 0 and 1000; <code>Range-50-50</code> would allow numbers between -50 and 50; and <code>Range-10--5</code> would allow numbers between -10 and -5.</p>
<p><strong>Smooth</strong>: Displays a simple continuous bar. If this option is not used and the bar does not have any custom colors, the bar's appearance is defined by the current system theme. Otherwise, the bar appears as a length of segments.</p>
<p><strong>Vertical</strong>: Makes the bar rise or fall vertically rather than move along horizontally.</p>
<p>The above options can be changed via <a href="../objects/GuiControl.htm#Opt">GuiCtrl.Opt</a> after the control is created.</p>

<h2 id="GroupBox">GroupBox</h2>
<p>Description: A rectangular border/frame, often used around other controls to indicate they are related. In this case, the last parameter is the title of the box, which if present is displayed at its upper-left edge.</p>
<p>例如:</p>
<pre>MyGui.Add("GroupBox", "w200 h100", "Geographic Criteria")
</pre>
<p>外观:</p>
<img src="../static/ctrl_group.png" alt="GroupBox" />
<p>By default, a GroupBox's title may have only one line of text. This can be overridden by specifying <code>Wrap</code> in <em>Options</em>.</p>
<p>To specify the number of rows inside the control (or its height and width), 请参阅 <a href="../objects/Gui.htm#PosSize">position and sizing of controls</a>.</p>

<span id="Tab2"></span><h2 id="Tab">Tab3</h2>
<p>Description: A large control containing multiple pages, each of which contains other controls. From this point forward, these pages are referred to as &quot;tabs&quot;.</p>
<p>There are three types of Tab control:</p>
<ul>
  <li><strong>Tab3</strong>: Fixes some issues which affect Tab2 and Tab. Controls are placed within an invisible "tab dialog" which moves and resizes with the tab control. The tab control is themed by default.</li>
  <li><strong>Tab2</strong>: Fixes rare redrawing problems in the original "Tab" control but introduces <a href="#Tab2_Issues">some other problems</a>.</li>
  <li><strong>Tab</strong>: Retained for backward compatibility because of <a href="#Tab_vs">differences in behavior</a> between Tab2/Tab3 and Tab.</li>
</ul>
<p>例如:</p>
<pre>MyGui.Add("Tab3",, ["General","View","Settings"])</pre>
<p>外观:</p>
<img src="../static/ctrl_tab.png" alt="Tab" />
<p id="ChooseTab">The last parameter above is an <a href="../objects/Array.htm">Array</a> of tab names. To have one of the tabs pre-selected when the window first appears, include in <em>Options</em> the word <strong>Choose</strong> followed immediately by the number of a tab to be pre-selected. For example, <code>Choose5</code> would pre-select the fifth tab (as with other options, it can also be a variable such as <code>"Choose" Var</code>). After the control is created, use <a href="../objects/GuiControl.htm#Value">Value</a>, <a href="../objects/GuiControl.htm#Text">Text</a> or <a href="../objects/GuiControl.htm#Choose">Choose</a> to change the selected tab, and <a href="../objects/GuiControl.htm#Add">Add</a> or <a href="../objects/GuiControl.htm#Delete">Delete</a> to add or remove tabs.</p>
<p id="TabCmd">After creating a Tab control, subsequently added controls automatically belong to its first tab. This can be changed at any time by following these examples (in this case, <em>Tab</em> is the <a href="../objects/GuiControl.htm">GuiControl object</a> of the first tab control and <em>Tab2</em> of the second one):</p>
<pre>Tab.<a href="../objects/GuiControl.htm#UseTab">UseTab</a>()  <em>; Future controls are not part of any tab control.</em>
Tab.UseTab(3)  <em>; Future controls are owned by the third tab of the current tab control.</em>
Tab2.UseTab(3)  <em>; Future controls are owned by the third tab of the second tab control.</em>
Tab.UseTab("Name")  <em>; Future controls are owned by the tab whose name starts with <i>Name</i> (not case sensitive).</em>
Tab.UseTab("Name", true)  <em>; Same as above but requires exact match (not case sensitive).</em></pre>
<p>It is also possible to use any of the examples above to assign controls to a tab or tab-control that does not yet exist (except in the case of the <em>Name</em> method). But in that case, the relative positioning options described below are not supported.</p>
<p id="Tab_Positioning1"><strong>Positioning</strong>: When each tab of a Tab control receives its first sub-control, that sub-control will have a special default position under the following conditions: 1) The X and Y coordinates are both omitted, in which case the first sub-control is positioned at the upper-left corner of the tab control's interior (with a standard <a href="../objects/Gui.htm#MarginX">margin</a>), and sub-controls beyond the first are positioned beneath the previous control; 2) The <a href="../objects/Gui.htm#PosPlus">X+n and/or Y+n</a> positioning options are specified, in which case the sub-control is positioned relative to the upper-left corner of the tab control's interior. 例如, specifying <code>x+10 y+10</code> would position the control 10 pixels right and 10 pixels down from the upper left corner.</p>
<p><strong>Current tab</strong>: <a href="../objects/GuiControl.htm#Value">GuiCtrl.Value</a> returns the position number of the currently selected tab (the first tab is 1, the second is 2, etc.). To get its text instead, use <a href="../objects/GuiControl.htm#Text">GuiCtrl.Text</a>. <a href="../objects/Gui.htm#Submit">MyGui.Submit</a> stores <a href="../objects/GuiControl.htm#Text">GuiCtrl.Text</a> by default, but stores <a href="../objects/GuiControl.htm#Value">GuiCtrl.Value</a> instead if the word <strong>AltSubmit</strong> is in the control's <em>Options</em>.</p>
<p><strong>Detecting tab selection</strong>: Whenever the user switches tabs, the <a href="../objects/GuiOnEvent.htm#Change">Change</a> event is raised.</p>
<p id="Tab_Keyboard"><strong>Keyboard navigation</strong>: The user may press <kbd>Control</kbd>+<kbd>PageDown</kbd>/<kbd>PageUp</kbd> to navigate from page to page in a tab control; if the keyboard focus is on a control that does not belong to a Tab control, the window's first Tab control will be navigated. <kbd>Control</kbd>+<kbd>Tab</kbd> and <kbd>Control</kbd>+<kbd>Shift</kbd>+<kbd>Tab</kbd> may also be used except that they will not work if the currently focused control is a multi-line Edit control.</p>
<p id="Tab_Limits"><strong>Limits</strong>: Each window may have no more than 255 tab controls. Each tab control may have no more than 256 tabs (pages). In addition, a tab control may not contain other tab controls.</p>

<h3 id="Tab_vs">Tab3 vs. Tab2 vs. Tab</h3>
<p id="Tab_Parent"><strong>Parent window</strong>: The parent window of a control affects the positioning and visibility of the control and tab-key navigation order. If a sub-control is added to an existing Tab3 control, its parent window is the "tab dialog", which fills the tab control's display area. Most other controls, including sub-controls of Tab or Tab2 controls, have no parent other than the GUI window itself.</p>
<p id="Tab_Positioning"><strong>Positioning</strong>: For Tab and Tab2, sub-controls do not necessarily need to exist within their tab control's boundaries: they will still be hidden and shown whenever their tab is selected or de-selected. This behavior is especially appropriate for the &quot;buttons&quot; style described below.</p>
<p>For Tab3, sub-controls assigned to a tab <em>before</em> the tab control is created behave as though added to a Tab or Tab2 control. All other sub-controls are visible only within the display area of the tab control.</p>
<p>If a Tab3 control is moved, its sub-controls are moved with it. Tab and Tab2 controls do not have this behavior.</p>
<p>In the rare case that <a href="WinMove.htm">WinMove</a> (or an equivalent DllCall) is used to move a control, the coordinates must be relative to the parent window of the control, which might not be the GUI (see <a href="#Tab_Parent">above</a>). By contrast, <a href="../objects/GuiControl.htm#Move">GuiCtrl.Move</a> takes GUI coordinates and <a href="ControlMove.htm">ControlMove</a> takes window coordinates, regardless of the control's parent window.</p>
<p id="Tab_Autosize"><strong>Autosizing</strong>: If not specified by the script, the width and/or height of the Tab3 control are automatically calculated at one of the following times (whichever comes first after the control is created):</p>
<ul>
  <li>The first time the Tab3 control ceases to be the current tab control. This can occur as a result of calling <a href="#TabCmd">GuiCtrl.UseTab</a> (with or without parameters) or creating another tab control.</li>
  <li>The first time <a href="../objects/Gui.htm#Show">MyGui.Show</a> is called for that particular Gui.</li>
</ul>
<p>The calculated size accounts for sub-controls which exist when autosizing occurs, plus the default margins. The size is calculated only once, and will not be recalculated even if controls are added later. If the Tab3 control is empty, it receives the same default size as a Tab or Tab2 control.</p>
<p>Tab and Tab2 controls are not autosized; they receive an arbitrary default size.</p>
<p id="Tab_TabOrder"><strong>Tab-key navigation order</strong>: The navigation order via the <kbd>Tab</kbd> key usually depends on the order in which the controls are created. When tab controls are used, the order also depends on the type of tab control:</p>
<ul>
  <li>Tab and Tab2 allow their sub-controls to be mixed with other controls within the tab-key order.</li>
  <li>Tab2 puts its tab buttons after its sub-controls in the tab-key order.</li>
  <li>Tab3 groups its sub-controls within the tab-key order and puts them after its tab buttons.</li>
</ul>
<p id="Tab_Notifs"><strong>Notification messages (Tab3)</strong>: Common and <a href="#Custom">Custom</a> controls typically send notification messages to their <a href="#Tab_Parent">parent window</a>. Any WM_COMMAND, WM_NOTIFY, WM_VSCROLL, WM_HSCROLL or WM_CTLCOLOR' messages received by a Tab3 control's <a href="#Tab_Parent">tab dialog</a> are forwarded to the GUI window and can be detected by using <a href="OnMessage.htm">OnMessage</a>. If the tab control is themed and the sub-control lacks the <a href="../objects/Gui.htm#BackgroundTrans">+BackgroundTrans</a> option, WM_CTLCOLORSTATIC is fully handled by the tab dialog and not forwarded. Other notification messages (such as custom messages) are not supported.</p>
<p id="Tab2_Issues"><strong>Known issues with Tab2</strong>:</p>
<ul>
  <li><a href="../objects/Gui.htm#BackgroundTrans">BackgroundTrans</a> has no effect inside a Tab2 control.</li>
  <li><a href="#ActiveX">WebBrowser</a> controls do not redraw correctly.</li>
  <li>AnimateWindow and possibly other Win32 API calls can cause the tab's controls to disappear.</li>
</ul>
<p id="Tab_Issues"><strong>Known issues with Tab</strong>:</p>
<ul>
  <li>Activating a GUI window by clicking certain parts of its controls, such as scrollbars, might redraw improperly.</li>
  <li><a href="../objects/Gui.htm#BackgroundTrans">BackgroundTrans</a> has no effect if the Tab control contains a ListView.</li>
  <li><a href="#ActiveX">WebBrowser</a> controls are invisible.</li>
</ul>

<h3>Tab Options</h3>
<p><strong>Choose</strong>: See <a href="#ChooseTab">above</a>.</p>
<p><strong>Background</strong>: Specify <code>-Background</code> (minus Background) to override the <a href="../objects/Gui.htm#BackColor">window's custom background color</a> and use the system's default Tab control color. Specify <code>+Theme -Background</code> to make the Tab control conform to the current desktop theme. However, most control types will look strange inside such a Tab control because their backgrounds will not match that of the tab control. This can be fixed for some control types (such as <a href="#Text">Text</a>) by adding BackgroundTrans to their options.</p>
<p><strong>Buttons</strong>: Creates a series of buttons at the top of the control rather than a series of tabs (in this case, there will be no border by default because the display area does not typically contain controls).</p>
<p><strong>Left/Right/Bottom</strong>: Specify one of these words to have the tabs on the left, right, or bottom side instead of the top. See <a href="../misc/Styles.htm#TCS_VERTICAL">TCS_VERTICAL</a> for limitations on Left and Right.</p>
<p><strong>Wrap</strong>: Specify <code>-Wrap</code> (minus Wrap) to prevent the tabs from taking up more than a single row (in which case if there are too many tabs to fit, arrow buttons are displayed to allow the user to slide more tabs into view).</p>
<p>To specify the number of rows of text inside the control (or its height and width), 请参阅 <a href="../objects/Gui.htm#PosSize">position and sizing of controls</a>.</p>
<p><strong>Icons in Tabs</strong>: An icon may be displayed next to each tab's name/text via <a href="SendMessage.htm">SendMessage</a>. This is demonstrated in the forum topic <a href="https://www.autohotkey.com/forum/topic6060.html">Icons in tabs</a>.</p>

<h2 id="StatusBar">StatusBar</h2>
<p>Description: A row of text and/or icons attached to the bottom of a window, which is typically used to report changing conditions.</p>
<p>例如:</p>
<pre>SB := MyGui.Add("StatusBar",, "Bar's starting text (omit to start off empty).")
SB.SetText(&quot;There are &quot; . RowCount . &quot; rows selected.&quot;)</pre>
<p>外观:</p>
<img src="../static/ctrl_status.png" alt="StatusBar" />
<p>The simplest use of a status bar is to call <a href="#SB_SetText">SB.SetText</a> whenever something changes that should be reported to the user. To report more than one piece of information, divide the bar into sections via <a href="#SB_SetParts">SB.SetParts</a>. To display icon(s) in the bar, call <a href="#SB_SetIcon">SB.SetIcon</a>.</p>

<h3 id="StatusBar_Methods">StatusBar Methods</h3>

<div class="methodShort" id="SB_SetText">
<h3>SetText</h3>
<p>Displays <em>NewText</em> in the specified part of the status bar, and returns 1 upon success and 0 upon failure.</p>
<pre class="Syntax">Success := SB.<span class="func">SetText</span>(NewText <span class="optional">, PartNumber := 1, Style := 0</span>)</pre>
<dl><dt>NewText</dt><dd>
<p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
<p>Up to two tab characters (`t) may be present anywhere in <em>NewText</em>:
 anything to the right of the first tab is centered within the part, and
 anything to the right of the second tab is right-justified.</p></dd><dt>PartNumber</dt><dd>
<p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
<p>If <em>PartNumber</em> is omitted, it defaults to 1. Otherwise, specify an integer between 1 and 256.</p></dd><dt>Style</dt><dd>
<p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
<p>If <em>Style</em> is omitted, it defaults to 0, which uses a traditional
 border that makes that part of the bar look sunken. Otherwise, specify 1
 to have no border or 2 to have border that makes that part of the bar 
look raised.</p></dd></dl>
</div>

<div class="methodShort" id="SB_SetParts">
<h3>SetParts</h3>
<p>Divides the bar into multiple sections according to the specified widths (in pixels), and returns a non-zero value (the status bar's <a href="../objects/GuiControl.htm#Hwnd">HWND</a>).</p>
<pre class="Syntax">Hwnd := SB.<span class="func">SetParts</span>(<span class="optional">Width1, Width2, ... Width255</span>)</pre>
<dl><dt>Width1 ... Width255</dt><dd>
<p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
<p>If all parameters are omitted, the bar is restored to having only a 
single, long part. Otherwise, specify the width of each part except the 
last (the last will fill the remaining width of the bar). 例如, <code>SB.SetParts(50, 50)</code> would create three parts: the first two of width 50 and the last one of all the remaining width.</p></dd></dl>
<p>Note: Any parts "deleted" by <code>SB.SetParts()</code> will start off with no text 
the next time they are shown (furthermore, their icons are automatically
 destroyed).</p></div>

<div class="methodShort" id="SB_SetIcon">
<h3>SetIcon</h3>
<p>Displays a small icon to the left of the text in the specified part, and returns the icon's handle.</p>
<pre class="Syntax">HICON := SB.<span class="func">SetIcon</span>(Filename <span class="optional">, IconNumber := 1, PartNumber := 1</span>)</pre>
<dl><dt>FileName</dt><dd>
<p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
<p>The path of an icon or image file. For a list of supported formats, 请参阅 <a href="#IconSupport">the Picture control</a>.</p>
<p>A <a href="../misc/ImageHandles.htm">bitmap or icon handle</a> can be used instead of a filename. 例如, <code>SB.SetIcon("HICON:" handle)</code>.</p></dd>
<dt>IconNumber</dt><dd>
<p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
<p>To use an icon group other than the first one in the file, specify its number for <em>IconNumber</em>. 例如, <code>SB.SetIcon("Shell32.dll", 2)</code> would use the default icon from the second icon group. If <em>IconNumber</em> is negative, its absolute value is assumed to be the resource ID of an icon within an executable file.</p></dd><dt>PartNumber</dt><dd>
<p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
<p>If <em>PartNumber</em> is omitted, it defaults to 1. Otherwise, specify an integer between 1 and 256.</p></dd></dl>
<p>Note: The HICON is a system resource that can be safely ignored by most 
scripts because it is destroyed automatically when the status bar's 
window is destroyed. Similarly, any old icon is destroyed when 
<code>SB.SetIcon()</code> replaces it with a new one. This can be avoided via:
</p>
<pre>MyGui.Opt("+LastFound")
<a href="SendMessage.htm">SendMessage</a>(0x40F, part_number - 1, my_hIcon, "msctls_statusbar321")  <em>; 0x40F is SB_SETICON.</em></pre></div>

<div class="methodShort" id="SB_SetProgress">
<h3>SetProgress</h3>
<p>Creates and controls a progress bar inside the status bar. This function is available at <a href="https://www.autohotkey.com/forum/topic37754.html">www.autohotkey.com/forum/topic37754.html</a></p></div>

<h3 id="StatusBar_Usage">StatusBar Usage</h3>
<p><strong>Reacting to mouse clicks</strong>: Whenever the user clicks on the bar, the <a href="../objects/GuiOnEvent.htm#Click">Click</a>, <a href="../objects/GuiOnEvent.htm#DoubleClick">DoubleClick</a> or <a href="../objects/GuiOnEvent.htm#ContextMenu">ContextMenu</a> event is raised, and the <em>Info</em> or <em>Item</em> parameter contains the part number. However, the part number might be a very large integer if the user clicks near the sizing grip at the right side of the bar.</p>
<p><strong>Font and color</strong>: Although the font size, face, and style can be set via <a href="../objects/Gui.htm#SetFont">MyGui.SetFont</a> (just like normal controls), the text color cannot be changed. The status bar's background color may be changed by specifying in <em>Options</em> the word <strong>Background</strong> followed immediately by a color name (see <a href="../misc/Colors.htm">color chart</a>) or RGB value (the 0x prefix is optional). Examples: <code>BackgroundSilver</code>, <code>BackgroundFFDD99</code>, <code>BackgroundDefault</code>.</p>
<p><strong>Hiding the StatusBar</strong>: Upon creation, the bar can be hidden via <code>MyStatusBar := MyGui.Add("StatusBar", "Hidden")</code>. To hide it sometime after creation, use <code>MyStatusBar.Visible := false</code>. To show it, use <code>MyStatusBar.Visible := true</code>. Note: Hiding the bar does not reduce the height of the window. If that is desired, one easy way is <code>MyGui.Show("<a href="../objects/Gui.htm#AutoSize">AutoSize</a>")</code>.</p>
<p><strong>Styles (rarely used)</strong>: See the <a href="../misc/Styles.htm#StatusBar">StatusBar styles table</a>.</p>
<p><strong>Known limitations</strong>: 1) Any control that overlaps the status bar might sometimes get drawn on top of it.  One way to avoid this is to dynamically shrink such controls via <a href="../objects/GuiOnEvent.htm#Size">Size</a> event. 2) There is a limit of one status bar per window.</p>
<p><strong>Example</strong>: <a href="TreeView.htm#ExAdvanced">Example #1</a> at the bottom of the TreeView page demonstrates a multipart status bar.</p>
<span id="IE_Control"></span><h2 id="ActiveX">ActiveX</h2>
<p>ActiveX components such as the MSIE browser control can be embedded into a GUI window by following this example:</p>
<pre>MyGui := Gui.New()
WB := MyGui.Add("ActiveX", "w980 h640", "<a href="http://msdn.microsoft.com/en-us/library/aa752085">Shell.Explorer</a>").Value  <em>; The last parameter is the name of the ActiveX component.</em>
WB.<a href="http://msdn.microsoft.com/en-us/library/aa752093">Navigate</a>("https://www.autohotkey.com/boards/")  <em>; This is specific to the web browser control.</em>
MyGui.Show()</pre>
<p>When the control is created, the ActiveX object can be retrieved via <a href="../objects/GuiControl.htm#Value">GuiCtrl.Value</a>.</p>
<p>To handle events exposed by the object, use <a href="ComObjConnect.htm">ComObjConnect</a> as demonstrated below:</p>
<pre>MyGui := Gui.New()
URL := MyGui.Add("Edit", "w930 r1", "https://www.autohotkey.com/boards/")
MyGui.Add("Button", "x+6 yp w44 Default", "Go").OnEvent("Click", "ButtonGo")
WB := MyGui.Add("ActiveX", "xm w980 h640", "Shell.Explorer").Value
<strong>ComObjConnect</strong>(WB, WB_events)  <em>; Connect WB's events to the WB_events class object.</em>
MyGui.Show()
<em>; Continue on to load the initial page:</em>
ButtonGo()

ButtonGo(*) {
    global
    WB.Navigate(URL.Value)
}

class WB_events {
    <a href="http://msdn.microsoft.com/en-us/library/aa768334">NavigateComplete2</a>(wb, NewURL) {
        global    
        URL.Value := NewURL  <em>; Update the URL edit control.</em>
    }
}</pre>
<p><a href="ComObjType.htm">ComObjType</a> can be used to determine the type of the retrieved object.</p>

<h2 id="Custom">Custom</h2>
<p>Other controls which are not directly supported by AutoHotkey can be also embedded into a GUI window. In order to do so, include in <em>Options</em> the word <strong>Class</strong> followed by the Win32 class name of the desired control. Examples:</p>
<pre>MyGui.Add("Custom", "ClassComboBoxEx32")  <em>; Adds a <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb775740.aspx">ComboBoxEx</a> control.</em>
MyGui.Add("Custom", "ClassScintilla")  <em>; Adds a <a href="https://scintilla.org/">Scintilla</a> control. Note that the SciLexer.dll library must be loaded before the control can be added.</em></pre>
<p>AutoHotkey uses the standard Windows control text routines when text is to be retrieved/replaced in the control via <code>MyGui.Add</code> or <code>GuiCtrl.Value</code>.</p>
<p><strong>Events</strong>: Since the meaning of each notification code depends on the control which sent it, <a href="../objects/GuiOnEvent.htm">OnEvent</a> is not supported for Custom controls. However, if the control sends notifications in the form of a WM_NOTIFY or WM_COMMAND message, the script can use <a href="../objects/GuiOnNotify.htm">OnNotify</a> or <a href="../objects/GuiOnCommand.htm">OnCommand</a> to detect them.</p>
<p>Here is an example that shows how to add and use an <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb761374.aspx">IP address control</a>:</p>
<pre>MyGui := Gui.New()
IP := MyGui.Add("Custom", "ClassSysIPAddress32 r1 w150 vIP")
IP.OnCommand(0x300, "IP_EditChange")  <em>; 0x300 = EN_CHANGE</em>
IP.OnNotify(-860, "IP_FieldChange")  <em>; -860 = IPN_FIELDCHANGED</em> 
MyGui.Add("Text", "wp vIPText")
MyGui.Add("Text", "wp y+m vIPField")
MyGui.Add("Button", "Default", "OK").OnEvent("Click", "OK_Click")
MyGui.Show()

IPCtrlSetAddress(IP, SysGetIPAddresses()[1])

OK_Click(this, *)
{
    this.Gui.Hide()
    MsgBox("You chose " IPCtrlGetAddress(this.Gui["IP"]))
    ExitApp()
}

IP_EditChange(this)
{
    this.Gui["IPText"].Text := "New text: " this.Gui["IP"].Text
}

IP_FieldChange(this, NMIPAddress)
{
    <em>; Extract info from the NMIPAddress structure.</em>
    iField := NumGet(NMIPAddress, 3*A_PtrSize + 0, "int")
    iValue := NumGet(NMIPAddress, 3*A_PtrSize + 4, "int")
    if (iValue &gt;= 0)
        this.Gui["IPField"].Text := "Field #" iField " modified: " iValue
    else
        this.Gui["IPField"].Text := "Field #" iField " left empty"
}

IPCtrlSetAddress(GuiCtrl, IPAddress)
{
    static WM_USER := 0x400
    static IPM_SETADDRESS := WM_USER + 101

    <em>; Pack the IP address into a 32-bit word for use with SendMessage.</em>
    IPAddrWord := 0
    Loop Parse IPAddress, "."
        IPAddrWord := (IPAddrWord * 256) + A_LoopField
    SendMessage(IPM_SETADDRESS, 0, IPAddrWord, GuiCtrl)
}

IPCtrlGetAddress(GuiCtrl)
{
    static WM_USER := 0x400
    static IPM_GETADDRESS := WM_USER + 102

    AddrWord := BufferAlloc(4)
    SendMessage(IPM_GETADDRESS, 0, AddrWord, GuiCtrl)
    Loop 4
        IPPart%A_Index% := NumGet(AddrWord, 4 - A_Index, "UChar")
    return IPPart1 "." IPPart2 "." IPPart3 "." IPPart4
}</pre>

<h2 id="Related">相关</h2>
<p><a href="ListView.htm">ListView</a>, <a href="TreeView.htm">TreeView</a>, <a href="../objects/Gui.htm#New">Gui.New</a>, <a href="../objects/Gui.htm">Gui object</a>, <a href="../objects/GuiControl.htm">GuiControl object</a>, <a href="../objects/Menu.htm">Menu object</a></p>

</body>
</html>